<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>公司制度 - 智慧考勤系统</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <style>
        .policy-container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .policy-category {
            margin-bottom: 30px;
            background: white;
            padding: 20px;
            border-radius: 4px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .policy-category h2 {
            color: #2c3e50;
            border-bottom: 1px solid #eee;
            padding-bottom: 10px;
            margin-top: 0;
        }
        .policy-list {
            list-style: none;
            padding: 0;
        }
        .policy-item {
            padding: 12px 15px;
            border-bottom: 1px solid #eee;
            transition: background 0.3s;
        }
        .policy-item:last-child {
            border-bottom: none;
        }
        .policy-item:hover {
            background: #f9f9f9;
        }
        .policy-item a {
            color: #3498db;
            text-decoration: none;
            display: block;
        }
        .policy-item a:hover {
            color: #2980b9;
        }
        .policy-date {
            font-size: 0.8em;
            color: #7f8c8d;
            margin-top: 5px;
        }
        .back-btn {
            display: inline-block;
            margin: 20px 0;
            padding: 10px 20px;
            background: #3498db;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            transition: background 0.3s;
        }
        .back-btn:hover {
            background: #2980b9;
        }
        .error-message {
            background: #f8d7da;
            color: #721c24;
            padding: 15px;
            border-radius: 4px;
            margin: 20px 0;
        }
        .search-container {
            margin-bottom: 20px;
        }
        .search-input {
            width: 70%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
        }
        .search-btn {
            padding: 10px 20px;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            margin-left: 10px;
        }
        .search-btn:hover {
            background: #2980b9;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>智慧考勤系统 - 公司制度</h1>
            <p class="subtitle">了解公司规章制度，共同维护良好工作秩序</p>
        </header>

        <main class="policy-container">
            <a href="/" class="back-btn">返回首页</a>
            
            <div class="search-container">
                <input type="text" id="policy-search" class="search-input" placeholder="搜索制度关键词...">
                <button id="search-btn" class="search-btn">搜索</button>
            </div>
            
            {% if error %}
            <div class="error-message">
                <p>{{ error }}</p>
            </div>
            {% else %}
                {% if policy_categories %}
                    {% for category, policies in policy_categories.items() %}
                    <section class="policy-category" id="category-{{ category }}">
                        <h2>{{ category }}</h2>
                        <ul class="policy-list">
                            {% for policy in policies %}
                            <li class="policy-item" data-title="{{ policy.title }}" data-content="{{ policy.content_preview if policy.content_preview else '' }}">
                                <a href="/policy/{{ policy.id }}">{{ policy.title }}</a>
                                <div class="policy-date">制度创建: {{ policy.created_at.strftime('%Y-%m-%d') if policy.created_at else '未知日期' }}</div>
                            </li>
                            {% endfor %}
                        </ul>
                    </section>
                    {% endfor %}
                {% else %}
                <div class="error-message">
                    <p>暂无制度信息</p>
                </div>
                {% endif %}
            {% endif %}
            
            <a href="/" class="back-btn">返回首页</a>
        </main>

        <footer>
            <p>&copy; 2023 智慧考勤系统 | <a href="/admin">管理员入口</a></p>
        </footer>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const searchInput = document.getElementById('policy-search');
            const searchBtn = document.getElementById('search-btn');
            const policyItems = document.querySelectorAll('.policy-item');
            
            // 搜索功能
            function searchPolicies() {
                const searchTerm = searchInput.value.toLowerCase();
                let hasResults = false;
                
                // 遍历所有制度项
                policyItems.forEach(item => {
                    const title = item.getAttribute('data-title').toLowerCase();
                    const content = item.getAttribute('data-content').toLowerCase();
                    
                    // 如果标题或内容包含搜索词，显示该项
                    if (title.includes(searchTerm) || content.includes(searchTerm)) {
                        item.style.display = 'block';
                        hasResults = true;
                    } else {
                        item.style.display = 'none';
                    }
                });
                
                // 处理分类标题的显示/隐藏
                document.querySelectorAll('.policy-category').forEach(category => {
                    const visibleItems = category.querySelectorAll('.policy-item[style="display: block"]');
                    category.style.display = visibleItems.length > 0 ? 'block' : 'none';
                });
                
                // 如果没有搜索结果，显示提示
                if (!hasResults && searchTerm) {
                    alert('没有找到匹配的制度');
                }
            }
            
            // 绑定搜索按钮点击事件
            searchBtn.addEventListener('click', searchPolicies);
            
            // 绑定回车键搜索
            searchInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    searchPolicies();
                }
            });
        });
    </script>
</body>
</html> 